package com.config;

/**
 * @Description swagger配置类
 * @Author JK
 * @Date 2024/1/2
 */

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                .select()
                // 指定扫描的包(切换成自己项目中的包)
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
                // 配置访问路径, 默认是/swagger-ui.html，可以自定义，但是需要和配置文件中的路径一致
                //此处将默认的/swagger-ui.html改为/doc.html
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 页面标题
                .title(" API ")
                // 描述
                .description("liang")
                // 版本号
                .version("0.0.1-SNAPSHOT")
                .build();
    }
}